package com.akuhome.resource.controller;

import com.akuhome.resource.dto.Form;
import com.akuhome.resource.enums.NeedType;
import com.akuhome.resource.service.FormService;
import com.akuhome.resource.service.need.AccNeedService;
import com.akuhome.resource.util.CodeEnumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/form")
public class FormController {
    @Autowired
    FormService formService;

    @GetMapping
    public Object getForm(){
        return new Form();
    }


    @GetMapping("/{id}")
    public Object getFormData(@PathVariable Integer id,String type){
        Form form;
        if(type == null){
            type = "all";
        }
        switch (type){
            case "acc":
                form = formService.getAccById(id);
                break;
            case "food":
                form = formService.getFoodById(id);
                break;
            case "class":
                form = formService.getClassroomById(id);
                break;
            case "all":
            default: form = formService.getAllById(id);
        }
        return  form;
    }

    @GetMapping("/uid/{uid}")
    public Object getFormDataByUid(@PathVariable String uid,String type){
        Form form;
        if(type == null){
            type = "all";
        }
        switch (type){
            case "acc":
                form = formService.getAccByUId(uid);
                break;
            case "food":
                form = formService.getFoodByUId(uid);
                break;
            case "class":
                form = formService.getClassroomByUId(uid);
                break;
            case "all":
            default: form = formService.getAllByUId(uid);
        }
        return  form;
    }

    @PutMapping
    public Object updateForm(@RequestBody Form form, int[] type){
        formService.updateForm(form,CodeEnumUtil.codeOf(NeedType.class,type));
        return null;
    }
}
